package cn.edu.jxust.core.infrastructure.mapper;


import cn.edu.jxust.common.domain.entity.SysResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author QiuKangming
 * @since 2020-07-11
 */

public interface ResourceMapper extends BaseMapper<SysResource> {

    /**
     * 查询子权限的条数, 资源id
     * @param id 资源id号
     * @return int
     */
    @Select("select count(id) from t_resource where parent_id = #{id} and status = 1")
    int selectSubPermsByPermissionId(Integer id);

    /**
     * 根据资源ids获取资源code列表
     * @param ids 资源ids
     * @return List<String>
     */
    @Select({
            "<script>",
            "SELECT resource_code FROM t_resource WHERE id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')' >",
            "#{id}",
            "</foreach>",
            "AND parent_id != 0 AND status = 1",
            "</script>"
    })
    List<String> getPermissionListByIds(@Param("ids") List<Integer> ids);

}
